//
// Created by 86150 on 2021/11/12.
//

#ifndef UNTITLED2_CHATROOM_H
#define UNTITLED2_CHATROOM_H
#include <vector>
#include <thread>
#include <sys/socket.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <queue>
#include <mutex>
#include "db_manager.h"
#include <pthread.h>

class chatroom
{
	private:
		const short self_port;
		int self_sock;
		sockaddr_in serv_addr;
		std::vector<int> clnt_socks;
		std::mutex mutex;
		db_manager db;
		void send_all_fake(char*, int, int);
		void send_all(char*, int);
		void to_browser();
		void error(std::string);
		void* chating2(void* arg);
		void chating(int, std::string);//cope the chaters
		void posting(int, std::string);//cope the posters
		void htmling(int);//cope the browser viewers
		//static pthread_mutex_t mutx;
		void debug(std::string now)
		{
			std::cout<<"DEBUG: "<<now<<"\n";
		}

	public:
		chatroom(short P = 5150);
		void chating_fake();
		void on();
		void on2();
		~chatroom() {};
};



#endif //UNTITLED2_CHATROOM_H
